package com.bilicraft;
import java.io.*;
public class FileOps {
	
	public String cmdPre = "SET APPDATA=.\\..\\..\\\n";
	//public String cmdPre = "start /D ";
	public String cmdsPath =  "SET PATH=\""+System.getProperty("java.home")+"\\bin\"";
	public String cmdsPre = "\nstart /D ";
	public String cmdBin = "\".minecraft\\bin\" ";
	public String cmdJavaw = "javaw ";
	public String cmdXms = "-Xms512m ";
	public String cmdXmx = "-Xmx1024m ";
	public String cmdD64 = "-d64 ";
	public String cmdCp = "-cp ";
	public String cmdJars = "jinput.jar;lwjgl.jar;lwjgl_util.jar;minecraft.jar ";
	public String cmdPath = "-Djava.library.path=\".\\natives\" net.minecraft.client.Minecraft ";
	public String cmdName = "bilibili";
	
	public FileOps(){
		
	}
	
	public boolean write(boolean d64) throws IOException{
		FileWriter fw = new FileWriter("launch.bat");  
		String s;
		if(d64)
			s = cmdPre+cmdsPath+cmdsPre+cmdBin+cmdJavaw+cmdXms+cmdXmx+cmdD64+cmdCp+cmdJars+cmdPath+cmdName;  
		else
			s = cmdPre+cmdsPath+cmdsPre+cmdBin+cmdJavaw+cmdXms+cmdXmx+cmdCp+cmdJars+cmdPath+cmdName;
		fw.write(s,0,s.length());  
		System.out.println("Written:"+s);
		fw.flush(); 	
		fw.close();
		return true;
	}
	
	public String read() throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("launch.bat")));
		String data = br.readLine();
		cmdsPath = br.readLine();
		//data = br.readLine();
		data = br.readLine(); 
		br.close();
		return data;
	}
	
	public void run() throws Exception{
		String command = "launch.bat";
		Runtime.getRuntime().exec(command);
	}
	
}
